home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_client_focus.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  7.6 KB  |  357 lines

  1. unit ntc_client_focus;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Variants,
  30.     Classes,
  31.     Graphics,
  32.     Controls,
  33.     Forms,
  34.     Dialogs,
  35.     Buttons,
  36.     StdCtrls,
  37.     ExtCtrls,
  38.     inifiles,
  39.  
  40.     ntc_client_form,
  41.     ntc_client_network;
  42.  
  43. const
  44.     default_timeout=500;
  45.  
  46. type
  47.     Tscope_focus = class(tform)
  48.         focus_panel: TPanel;
  49.         focus_minus_button: TSpeedButton;
  50.         focus_plus_button: TSpeedButton;
  51.         speed_label: TLabel;
  52.         speed_box: TPanel;
  53.         first_speed_button: TSpeedButton;
  54.         timeout_duration_label: TLabel;
  55.         millisecond_label: TLabel;
  56.         timeout_duration_edit: TEdit;
  57.         stop_button: TSpeedButton;
  58.         focus_timer: TTimer;
  59.  
  60.         { form functions }
  61.         procedure formcreate(
  62.             Sender:TObject);
  63.  
  64.         procedure form_close_query(
  65.                     Sender: TObject;
  66.             var CanClose: Boolean);
  67.  
  68.         procedure flip_buttons(
  69.             toggle:boolean);
  70.  
  71.         { communications }
  72.         function send_request_check(
  73.             m:string)
  74.             :response_type;
  75.  
  76.         { configuration }
  77.         procedure load_settings;
  78.  
  79.         procedure save_settings;
  80.  
  81.         { events }
  82.         procedure FormShow(
  83.             Sender: TObject);
  84.  
  85.         procedure adjust;
  86.  
  87.         procedure check_activate(
  88.             Sender: TObject);
  89.  
  90.         procedure speed_button_click(
  91.             Sender: TObject);
  92.  
  93.         procedure stop_buttonClick(
  94.             Sender: TObject);
  95.  
  96.         procedure focus_minus_buttonClick(
  97.             Sender: TObject);
  98.  
  99.         procedure focus_plus_buttonClick(
  100.             Sender: TObject);
  101.  
  102.         procedure enable_focus_timer;
  103.  
  104.         procedure focus_timerTimer(
  105.             Sender: TObject);
  106.  
  107.         procedure timeout_duration_editChange(
  108.             Sender: TObject);
  109.  
  110.     private
  111.         { Private declarations }
  112.         speed_group_index:integer;
  113.     public
  114.         { Public declarations }
  115.         focus_speeds,
  116.         start_focus_speed:integer;
  117.         can_focus:boolean;
  118.         focus_timeout:integer;
  119.         { configuration }
  120.         dimensions:dimensions_record;
  121.  
  122.         { events }
  123.         procedure check_visible_and_show_hide(
  124.             sender:tobject);
  125.  
  126.         procedure hide_form;
  127.         procedure show_form;
  128.     end;
  129.  
  130. var
  131.     scope_focus: Tscope_focus;
  132.  
  133. implementation
  134.  
  135. uses
  136.     ntc_client_control;
  137.  
  138. {$R *.dfm}
  139.  
  140.     { --------------
  141.         form functions
  142.         -------------- }
  143.  
  144. procedure Tscope_focus.formcreate(
  145.     Sender:TObject);
  146. begin
  147.     speed_group_index:=1;
  148.     can_focus:=false;
  149.     flip_buttons(false);
  150.     load_settings;
  151. end;
  152.  
  153. procedure tscope_focus.form_close_query(
  154.             Sender: TObject;
  155.     var CanClose: Boolean);
  156. begin
  157.     canclose:=false;
  158.     visible:=false;
  159.     with dimensions do
  160.         begin
  161.             form_top:=top;
  162.             form_left:=left;
  163.         end;
  164. end;
  165.  
  166.     { ---------
  167.         utilities
  168.         --------- }
  169.  
  170. function tscope_focus.send_request_check(
  171.     m:string)
  172.     :response_type;
  173. begin
  174.     result:=scope_network.send_request_check(m);
  175. end;
  176.  
  177. procedure Tscope_focus.flip_buttons(
  178.     toggle:boolean);
  179. begin
  180.     millisecond_label.enabled:=toggle;
  181.     focus_minus_button.enabled:=toggle;
  182.     focus_plus_button.enabled:=toggle;
  183.     timeout_duration_edit.enabled:=toggle;
  184.     speed_label.enabled:=toggle;
  185.     speed_box.enabled:=toggle;
  186.     first_speed_button.enabled:=toggle;
  187.     stop_button.enabled:=toggle;
  188. end;
  189.  
  190.     { -------------
  191.         focus control
  192.         ------------- }
  193.  
  194. procedure Tscope_focus.stop_buttonClick(
  195.     Sender: TObject);
  196. begin
  197.     send_request_check('stop_focus');
  198.     focus_timer.enabled:=false;
  199. end;
  200.  
  201.     { -------------
  202.         configuration
  203.         ------------- }
  204.  
  205. procedure tscope_focus.load_settings;
  206. begin
  207.     ini_file:=tinifile.create(application_path+'client.ini');
  208.     with ini_file do
  209.         begin
  210.             can_focus:=ReadBool('focus','can_focus',false);
  211.             focus_timeout:=readinteger('focus','timeout',default_timeout);
  212.             timeout_duration_edit.text:=inttostr(focus_timeout);
  213.             start_focus_speed:=readinteger('focus','start_focus_speed',1);
  214.             focus_speeds:=readinteger('focus','focus_speeds',2);
  215.             if (focus_speeds>9) or
  216.                  (focus_speeds<2) then
  217.                 focus_speeds:=2;
  218.             { form }
  219.             scope.get_dimensions(scope_focus,@dimensions,'focus',ini_file);
  220.             left:=dimensions.form_left;
  221.             top:=dimensions.form_top;
  222.             visible:=readbool('focus','visible',false);
  223.         end;
  224.     ini_file.free;
  225. end;
  226.  
  227. procedure tscope_focus.save_settings;
  228. begin
  229.     with ini_file do
  230.         begin
  231.             writeBool('focus','can_focus',can_focus);
  232.             writeinteger('focus','timeout',focus_timeout);
  233.             writeinteger('focus','start_focus_speed',start_focus_speed);
  234.             writeinteger('focus','focus_speeds',focus_speeds);
  235.             { form }
  236.             scope.find_vdu(scope_focus,@dimensions);
  237.             scope.write_dimensions(@dimensions,left,top,'focus',ini_file);
  238.             writebool('focus','visible',visible);
  239.         end;
  240. end;
  241.  
  242.     { ------
  243.         events
  244.         ------ }
  245.  
  246. procedure Tscope_focus.FormShow(
  247.     Sender: TObject);
  248. begin
  249.     with dimensions do
  250.         begin
  251.             top:=form_top;
  252.             left:=form_left;
  253.         end;
  254.     scope_control.update_speed_group(
  255.         speed_box,
  256.         first_speed_button,
  257.         start_focus_speed,
  258.         focus_speeds,
  259.         speed_button_click,
  260.         can_focus);
  261. end;
  262.  
  263. procedure tscope_focus.adjust;
  264. begin
  265.     with dimensions do
  266.         begin
  267.             form_top:=trunc(form_top/last_screen_height*current_height);
  268.             form_left:=trunc(form_left/last_screen_width*current_width);
  269.         end;
  270.     if visible then
  271.         show;
  272. end;
  273.  
  274. procedure tscope_focus.check_visible_and_show_hide(
  275.     sender:tobject);
  276. begin
  277.     if visible then
  278.         hide_form
  279.     else
  280.         show_form;
  281.     scope.show_hide(sender,visible);
  282. end;
  283.  
  284. procedure tscope_focus.hide_form;
  285. begin
  286.     with dimensions do
  287.         begin
  288.             form_top:=top;
  289.             form_left:=left;
  290.         end;
  291.     Visible:=false;
  292. end;
  293.  
  294. procedure tscope_focus.show_form;
  295. begin
  296.     Visible:=true;
  297. end;
  298.  
  299. procedure Tscope_focus.check_activate(
  300.     Sender: TObject);
  301. begin
  302.     scope.form_activate(scope_focus,@dimensions);
  303. end;
  304.  
  305. procedure Tscope_focus.speed_button_click(
  306.     Sender: TObject);
  307. begin
  308.     speed_group_index:=scope_control.set_slew_speed(speed_box);
  309. end;
  310.  
  311. procedure Tscope_focus.focus_minus_buttonClick(
  312.     Sender: TObject);
  313. begin
  314.     if (scope_type=autostar_type) or (scope_type=lx200_type) then
  315.          send_request_check('focus(speed='+inttostr(speed_group_index)+
  316.         ',dir=-,timeout='+inttostr(focus_timeout)+')');
  317. end;
  318.  
  319. procedure Tscope_focus.focus_plus_buttonClick(
  320.     Sender: TObject);
  321. begin
  322.     if (scope_type=autostar_type) or (scope_type=lx200_type) then
  323.          send_request_check('focus(speed='+inttostr(speed_group_index)+
  324.         ',dir=+,timeout='+inttostr(focus_timeout)+')');
  325. end;
  326.  
  327. procedure tscope_focus.enable_focus_timer;
  328. begin
  329.     focus_timer.interval:=focus_timeout;
  330.     focus_timer.enabled:=true;
  331. end;
  332.  
  333. procedure Tscope_focus.focus_timerTimer(
  334.     Sender: TObject);
  335. begin
  336.     focus_timer.enabled:=false;
  337.     if not (send_request_check('stop_focus')>=[exit_ok]) then
  338.         begin
  339.             scope_control.write_status_log('Unable to stop focus');
  340.             focus_timer.interval:=focus_timeout;
  341.             focus_timer.enabled:=true;
  342.         end;
  343. end;
  344.  
  345. procedure Tscope_focus.timeout_duration_editChange(
  346.     Sender: TObject);
  347. begin
  348.     focus_timeout:=strtointdef(timeout_duration_edit.text,default_timeout);
  349.     if focus_timeout<0 then
  350.         begin
  351.             focus_timeout:=default_timeout;
  352.             timeout_duration_edit.text:=inttostr(focus_timeout);
  353.         end;
  354. end;
  355.  
  356. end.
  357.